package com.example.example.controller;

import com.example.example.domain.MessageVO;
import com.example.example.result.Result;
import com.example.example.service.impl.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息控制器
 */
@Slf4j
@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 获取所有消息列表
     *
     * @return 消息列表
     */
    @GetMapping("/list")
    public Result<List<MessageVO>> getMessages(@RequestParam Object chatId) {
        if (chatId.toString().isBlank()) {
            return Result.fail("参数错误");
        }
        List<MessageVO> voList = messageService.getMessageVOs(chatId);
        return Result.ok(voList);
    }

    /**
     * 删除所有消息
     *
     * @return 操作结果
     */
    @DeleteMapping("/deleteAll")
    public Result<String> deleteAllMessages(@RequestParam Object chatId) {
        if (chatId.toString().isBlank()) {
            return Result.fail("参数错误");
        }
        messageService.deleteMessages(chatId);
        return Result.ok("删除成功");
    }

    /**
     * 获取MemoryId
     *
     * @return MemoryId
     */
    @GetMapping("/getMemoryId")
    public Result<String> getMemoryId() {
        return Result.ok(messageService.getMemoryId());
    }
}
